package com.cqs.learning.spring.cloud.producer.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;

import java.io.*;

public class DoubanService {


    public JSONObject mockReqMovie(){
        //Java读取的resource目录下的文件
        InputStream resourceAsStream = DoubanService.class.getResourceAsStream("data/douban_movies.json");
        if (resourceAsStream == null) {
            try {
                resourceAsStream = new FileInputStream("producer2/src/main/resources/data/douban_movies.json");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            String s = IOUtils.toString(resourceAsStream);
            System.out.println(s);
            JSONObject jsonObject = JSON.parseObject(s);
            return jsonObject;
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }


    public static void main(String[] args) {
        new DoubanService().mockReqMovie();
    }
}
